package com.qms.app.controller;

import com.qms.app.bean.Logs;
import com.qms.app.service.LogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/logs")
public class LogsController {
    @Autowired
    private LogsService logsService;

    @RequestMapping("/listLogs")
    public Map<String,Object > listLogs(Integer page, Integer rows, String opername){
        Map<String,Object >  map=new HashMap<>();
        map.put("total",logsService.countLogs(opername));
        map.put("rows",logsService.listLogs(page,rows,opername));
        return  map;
    }
    //统计访问次数
    @RequestMapping("/countTimes")
    public Map<String,Object >countTimes(){
        Map<String,Object >  map=new HashMap<>();
        //访问人
        List<String> names=new ArrayList<>();
        //统计的次数
        List<Integer> times=new ArrayList<>();
        List<Logs> logs = logsService.countLogsTimes();

        for (Logs log : logs) {
            names.add(log.getOpername());
            times.add(log.getTatal());
        }

        // 将属性名字  传递给前端 前端中通过此处设置的属性名  获取信息
        map.put("names",names);
        map.put("times",times);
        return map;
    }
}
